<template>
  <div>
    <TopFilter ref="TopFilterss" :list="topFilterInit" :cols="3" :collapse="collapse" labelWidth="95" @filterChange="changeHandle"></TopFilter>
    <!-- table -->
    <FilterTable
      ref="table"
      :columns="columns"
      :params="fetchParams"
      :fetchapi="fetchapi"
      :datakey="'records'"
      :onColumnsChange="(columns) => (this.columns = columns)"
      :onRowSelectChange="selectChange"
    >
    </FilterTable>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right',
      }"
    >
      <multiuse-button type="primary" :click="saveDialog.bind()">添加</multiuse-button>
      <multiuse-button @click="closeDialog">关 闭</multiuse-button>
    </div>
    <BaseDialog :visible.sync="visibleAdd" :title="'选择经销商'" destroyOnClose width="850px" :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}">
      <DealerList @close="closeAdd" @save="saveAdd"></DealerList>
    </BaseDialog>
  </div>
</template>
<script>
import selectDelearPage from './selectDelearPage.vue';
import { qurListByPage, getPartType } from '@/api/claim/factory/ClaimAccountSummarySubmit';
import DealerList from '@/pages/claimDemage/tools/DealerList.vue';
import { getAppId } from '@/assets/js/auth';
import moment from "moment";

export default {
  props: ['rowData'],
  components: {
    DealerList
  },
  data() {
    return {
      dataList: [],
      visible: false,
      visibleDrawer: false,
      collapse: true,
      chakanFlag: false,
      dealerFlag: false,
      infoId: null,
      editRow: {},
      // rowData: {},
      topFilterInit: this.topFilterInitFun(),
      flterValue: {}, //参数
      fetchapi: qurListByPage,
      columns: this.creatHeader(),
      fetchParams: { carType: this.rowData.sumType,batchStatus:55481004,statusForFlag:3 }, //ipa 接口
      selectedRows: [], //选中经销商
      visibleAdd: false,
    };
  },
  created() {
    // this.chuqi();
    console.log(22);
    console.log(this.rowData);
  },
  methods: {
    //选中
    selectChange(rows) {
      this.selectedRows = rows;
      console.log(rows);
    },
    //保存
    saveDialog() {
      this.$emit('save', this.selectedRows);
    },
    //取消操作
    closeDialog() {
      this.$emit('close', { visible: false, data: this.selectedRows, type: 'close' });
    },
    closeDealer() {
      this.dealerFlag = false;
    },
    saveDealer(obj) {
      this.topFilterInit.map((x) => {
        if ('dealerCode' == x.fieldName) {
          x.initialValue = obj[0].dealerCode;
        }
      });
      this.dealerFlag = false;
    },
    chooseDealerNo() {
      this.visibleAdd = true;
    },
    //翻译
    async chuqi() {
      const res = await getPartType({ type: 5546 });
      if (res.resultCode == 200) {
        this.topFilterInit.find((x) => x.fieldName == 'settleStatus').initialValue = '';
        this.topFilterInit.find((x) => x.fieldName == 'settleStatus').itemList = res.data.map((y) => ({ text: y.codeCnDesc, value: y.codeId }));
      }
    },
    //搜索数据
    topFilterInitFun() {
      return [
        {
          type: 'INPUT',
          label: '经销商代码',
          fieldName: 'dealerCode',
          placeholder: '请输入',
          initialValue: '',
          readonly: true,
          unitRender: (p) => {
            return (
              <div>
                <multiuse-button icon="el-icon-search" onClick={() => this.chooseDealerNo()} />
              </div>
            );
          },
        },
        { type: 'INPUT', label: '结算单号', fieldName: 'batchNo', placeholder: '请输入', initialValue: '' },
        {
          type: 'RANGE_DATE',
          label: '开票时间',
          fieldName: 'beginApproveDate|endApproveDate',
          placeholder: '请输入',
          initialValue: '',
          rules: [{ required: true, message: '请选择日期', trigger: 'change' }]
        },
        {
          type: 'RANGE_DATE',
          label: '提交时间',
          fieldName: 'beginSubmitDate|endSubmitDate',
          placeholder: '请输入',
          initialValue: '',
        },
      ];
    },
    //搜索获取数据
    changeHandle(val) {
      if(!val.beginApproveDate) {
        this.$notify.warning({ title: '提示信息', message: '开票开始日期不可为空！' });
        return
      }
      if(!val.endApproveDate) {
        this.$notify.warning({ title: '提示信息', message: '开票结束日期不可为空！' });
        return
      }
      if(getAppId() == 'arcfox') {
        if (moment(moment(val.endApproveDate).format('YYYY-MM-DD')).diff(moment(val.beginApproveDate), 'months', true) > 12) {
          this.$notify.warning({ title: '提示信息', message: '开票日期跨度不可超过十二个月！' });
          return
        }
      } else {
        if (moment(moment(val.endApproveDate).format('YYYY-MM-DD')).diff(moment(val.beginApproveDate), 'months', true) > 12) {
          this.$notify.warning({ title: '提示信息', message: '开票日期跨度不可超过十二个月！' });
          return
        }
      }
      this.fetchParams = Object.assign({ carType: this.rowData.sumType ,batchStatus:55481004,statusForFlag:3}, this.fetchParams, val);
    },
    //table表头和数据源
    creatHeader() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: (props) => {
            return <span>{props.row.index + 1}</span>;
          },
        },
        { title: '经销商代码', dataIndex: 'dealerCode', sorter: true },
        { title: '经销商名称', dataIndex: 'dealerName', sorter: true },
        { title: '结算批次单号', dataIndex: 'batchNo', sorter: true },
        { title: '索赔车辆属性', dataIndex: 'carTypeStr', sorter: true },
        { title: '索赔单数', dataIndex: 'claimNum', sorter: true },
        { title: '发票张数', dataIndex: 'invoiceSheets', sorter: true },
        { title: '结算金额', dataIndex: 'settleSum', sorter: true },
        { title: '索赔金额', dataIndex: 'claimSum', sorter: true },
        { title: '考核金额', dataIndex: 'assessSum', sorter: true },
        { title: '税额', dataIndex: 'settleStatusStr', sorter: true },
        { title: '邮寄时间', dataIndex: 'createdAt', sorter: true },
        { title: '工时费（元）', dataIndex: 'labourAmount', sorter: true },
        { title: '配件费用（元）', dataIndex: 'partAmount', sorter: true },
        { title: '附加费（元）', dataIndex: 'addAmount', sorter: true },
        // { title: '配件缺失索赔', dataIndex: 'createdAt', sorter: true },
        // { title: '配件缺失索赔金额', dataIndex: 'createdAt', sorter: true },
        { title: '让渡数量', dataIndex: 'rangDuNum', sorter: true },
        { title: '让渡金额', dataIndex: 'rangDuAmount', sorter: true },
        { title: '正常索赔', dataIndex: 'zhengChangAmount', sorter: true },
        // { title: '批量活动', dataIndex: 'createdAt', sorter: true },
        { title: '喷漆索赔', dataIndex: 'penQiAmount', sorter: true },
        // { title: '快递号', dataIndex: 'createdAt', sorter: true },
        //  { title: '主键', dataIndex: 'batchId', hidden: true }
      ];
    },
    //选中
    selectChange(rows) {
      this.selectedRows = rows;
      console.log(this.selectedRows);
    },
    close() {
      this.visible = false;
      this.fetchParams = { ...this.fetchParams };
    },
    chooseOrderNo(val) {
      this.rowData = val;
      this.visible = true;
    },
    chakan(val) {
      this.rowData = val;
      this.chakanFlag = true;
    },
    save(obj) {
      this.visible = false;
      this.fetchParams = { ...this.fetchParams };
    },
    add() {
      this.visibleAdd = true;
    },
    chakanclose() {
      this.chakanFlag = false;
      this.fetchParams = { ...this.fetchParams };
    },
    chakanAdd() {
      this.chakanFlag = false;
      this.fetchParams = { ...this.fetchParams };
    },
    saveAdd(val) {
      this.topFilterInit.find(x => x.fieldName == 'dealerCode').initialValue = val[0].dealerCode;
      this.dealer = {...val[0]};
      this.visibleAdd = false;
    },
    closeAdd() {
      this.visibleAdd = false;
    },
  },
};
</script>

<style lang="less" scoped></style>
